#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: func2.py 
@version:
@time: 2024/01/22 
"""


class Solution(object):
    @staticmethod
    def find_num(nums):
        def func(low, high):
            if low == high:
                return nums[low]
            mid = (high - low) // 2 + low
            head = func(low, mid)
            tail = func(mid + 1, high)
            if head == tail:
                return tail
            head_count = sum(1 for i in range(low, high + 1) if nums[i] == head)
            tail_count = sum(1 for i in range(low, high + 1) if nums[i] == tail)
            return head if head_count > tail_count else tail

        return func(0, len(nums) - 1)


print(Solution().find_num([1, 2, 1, 2, 1]))
